package aplicacao;

import java.awt.event.ActionListener;  
  
  
import javax.swing.JLabel;  
import javax.swing.JProgressBar;
import javax.swing.Timer;

public class timerProgresso {
  JProgressBar pb;  
  static int number = 0;
  private boolean parar;

  public timerProgresso(JProgressBar progress) {
      pb = progress;
      parar = false;  
  }

  public timerProgresso() {
    parar = false;
  }
  
  
  
  public void go() {  
      ActionListener action = new ActionListener() {  
          public void actionPerformed(@SuppressWarnings("unused") java.awt.event.ActionEvent e) {  
              if (timerProgresso.this.parar){
                if (e.getSource() instanceof Timer){
                  Timer t = (Timer) e.getSource();
                  t.stop();
                }
              } else {
                if (pb != null){
                  int value = timerProgresso.this.pb.getValue() + 1;
                  timerProgresso.this.pb.setValue(value);
                }  
              }
              number++;
          }  
      };  
      Timer t = new Timer(1000, action);  
      t.start();  
  }
  
  public void stop(){
    parar = true;
  }
  
}
